package com.dk.controller;

import com.dk.result.Result;
import com.dk.service.CarsService;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("top")
@Api
@ApiOperation("排行榜")
@RefreshScope//自动刷新配置
public class TopController {

    @Autowired
    private CarsService carService;




    //人气榜
    @GetMapping("moods")
    @ApiOperation(value = "人气榜")
    public Result moods(){
        return Result.OK().setData(carService.getAll());
    }



//    预热
//    使用定时器完成定时预热
    @PostMapping("preheat")
    @XxlJob(value = "lastTask")
    @ApiOperation(value = "更新缓存")
    public Result preheat (){
        carService.getTime();
        return Result.OK();
    }

    //上新榜
    @GetMapping("putaway")
    @ApiOperation(value = "上新榜")
    public Result putaway(){
        return Result.OK().setData(carService.getPutaWay());
    }



}
